<template>
  <div>
    <div id="icon-menu">
      <ul>
        <li>
          <div class="icon-menu-item" @click="goHome">
            <i class="el-icon-third-home"></i>
          </div>
        </li>
        <li>
          <div class="icon-menu-item" @click="goGuestbook">
            <i class="el-icon-edit-outline"></i>
          </div>
        </li>
        <li>
          <div class="icon-menu-item" @click="goLink">
            <i class="el-icon-link"></i>
          </div>
        </li>
        <li>
          <div class="icon-menu-item" @click="goSearch">
            <i class="el-icon-search"></i>
          </div>
        </li>
        <li>
          <div class="icon-menu-item" @click="goUCenter">
            <el-badge :is-dot="this.$store.state.wsNotify">
              <i class="el-icon-third-person" v-if="!this.$store.getters.token || !this.$store.getters.userInfo.avatar"></i>
              <el-avatar :src="this.$store.getters.userInfo.avatar" v-if="this.$store.getters.token && this.$store.getters.userInfo.avatar"></el-avatar>
            </el-badge>
          </div>
        </li>
      </ul>
    </div>
    <div id="web-icon-menu">
      <div class="web-icon-menu-item" :title="this.$store.getters.token ? this.$store.getters.userInfo.nickname : '登录'" @click="goUCenter">
        <el-badge :is-dot="this.$store.state.wsNotify">
          <i class="el-icon-third-person" v-if="!this.$store.getters.token || !this.$store.getters.userInfo.avatar"></i>
          <el-avatar :src="this.$store.getters.userInfo.avatar" v-if="this.$store.getters.token && this.$store.getters.userInfo.avatar"></el-avatar>
        </el-badge>
      </div>
    </div>
  </div>

</template>

<script>
  export default {
    name: "IconMenu",
    data() {
      return {}
    },
    methods: {
      goHome() {
        this.$router.push({name: 'index', query: {page: 1}})
      },
      goGuestbook() {
        this.$router.push({name: 'guestbook'})
      },
      goLink() {
        this.$router.push({name: 'link'})
      },
      goSearch() {
        switch (this.$store.state.searchShow) {
          case 'show':
            this.$store.state.searchShow = 'show-i';
            break
          case 'show-i':
            this.$store.state.searchShow = 'noshow';
            break
          case 'noshow':
            this.$store.state.searchShow = 'show-i';
            break
        }
      },
      goUCenter() {
        if (!this.$store.getters.token) {
          if (this.$route.name === 'login') {
            return
          }
          this.$router.replace({name: 'login', query: {redirect: this.$router.currentRoute.fullPath}})
        }
        // else {
        //   this.$router.push({name: 'ucenter'})
        // }
      }
    },
    mounted() {
    }
  }
</script>

<style scoped>

  #icon-menu {
    display: none;
    position: fixed;
    right: 30px;
    bottom: 60px;
    z-index: 5;
  }

  #icon-menu ul li {
    padding: 0 !important;
    height: unset;
    line-height: unset;
    margin-bottom: 10px;
  }

  #web-icon-menu {
    position: fixed;
    right: 30px;
    bottom: 70px;
    z-index: 5;
  }

  #web-icon-menu .el-badge {
    height: 40px;
    line-height: 40px;
  }

  .icon-menu-item, .web-icon-menu-item {
    background-color: #FFF;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
    -webkit-box-shadow: 0 0 6px rgba(0, 0, 0, .12);
    box-shadow: 0 0 6px rgba(0, 0, 0, .12);
    cursor: pointer;
    z-index: 5;
    color: #409EFF;
  }

  .el-button--text {
    padding: unset;
  }

  .el-icon-third-person:before {
    font-size: 14px;
  }

</style>
